import requests
from lxml import etree

form_data = {
    'type': 1,
    'name': '',
    'area': '',
    'city': '不限',
    'city1': '',
    'city2': '',
    'xmxz': 0,
    'state': 0,
    'money': '',
    'money1': '',
    'number': 0,
    'fid1': '',
    'fid2': '',
    'fid3': '',
    'order': 0,
    'page': 1,
    'include': 0,
}
headers = {
    'Accept': 'application/json, text/javascript, */*; q=0.01',
    'Accept-Encoding': 'gzip, deflate, br, zstd',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Connection': 'keep-alive',
    'Content-Length': '138',
    'Content-Type': 'application/x-www-form-urlencoded',
    'Cookie': '__jsluid_s=21b11e7adb3fb3aac58677d333f07cb8;Cookies-01=78968004;__jsl_clearance_s=1744784111.132|0|fII7V8QaRu8F4HX%2Bu7RfUiS83pI%3D;ASP.NET_SessionId=lipein3l0qq5mptk5f5umbkf;Hm_lvt_5698cdfa8b95bb873f5ca4ecf94ac150=1744784134;HMACCOUNT=80BCC7E24F98D420;Hm_lpvt_5698cdfa8b95bb873f5ca4ecf94ac150=1744786463',
    'Host': 'www1.rmfysszc.gov.cn',
    'Origin': 'https://www1.rmfysszc.gov.cn',
    'Referer': 'https://www1.rmfysszc.gov.cn/projects.shtml',
    'Sec-Ch-Ua': '\"Google Chrome\";v=\"135\", "Not-A.Brand\";v=\"8\", \"Chromium\";v=\"135\"',
    'Sec-Ch-Ua-Mobile': '?0',
    'Sec-Ch-Ua-Platform': "\"Windows\"",
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/135.0.0.0 Safari/537.36',
    'X-Requested-With': 'XMLHttpRequest'
}
resp = requests.post('https://www1.rmfysszc.gov.cn/ProjectHandle.shtml', data=form_data, headers=headers)
# print(resp.text)
e = etree.HTML(resp.text)
# 标题
titles = e.xpath('//div[@class="product"]/div[@class="p_img"]/a/@title')
# 图片
images = e.xpath('//div[@class="product"]/div[@class="p_img"]/a/img/@src')
# 起拍价
price1 = e.xpath('//div[@class="product"]/div[2]/p[1]/strong/text() | //div[@class="product"]/p/strong/text()')
# 评估价
price2 = e.xpath('//div[@class="product"]/div[2]/p[2]/span/text()')
# 开始时间
times = e.xpath('//div[@class="product"]/div[2]/p[3]/span/text()')

# print(f"标题{len(titles)}条")
# print(titles)
# print(f"图片{len(images)}条")
# print(images)
# print(f"起拍价{len(price1)}条")
# print(price1)
# print(f"评估值{len(price2)}条")
# print(price2)
# print(f"开始时间{len(times)}条")
# print(time)
dataList = []
for index in range(len(titles)):
    dataList.append({
        'title': titles[index],
        'image': images[index],
        'price1': price1[index],
        'price2': price2[index],
        'time': times[index],
    })
print(dataList)
